import api from "../api/api";
import sensors from "@/js_sdk/Sensorsdata-UniPlugin-JS/Sensorsdata-UniPlugin-JS/index.js";

/**
 * 莫凡 阿里云日志服务
 * @param {Object} data
 */
async function aliYunMorefunLogs(data){
	try{
		const _anonymousID = sensors.getAnonymousID();
		const res = uni.getStorageSync("uniLoginInfo");
		let _obj = {
			anonymousID: _anonymousID || "",
			env: api.environment || "",
			openid: res.openid || "",
			unionId: res.unionId || "",
			...data
		}
		await uni.request({
		  url: "https://macallan.cn-zhangjiakou.log.aliyuncs.com/logstores/macallan-wx/track?APIVersion=0.6.0",
		  method: 'POST',
		  data: {
				"__logs__": [_obj]
			},
		  timeout: 10000,
		  header: {
		    'Content-Type': 'application/json',
		  }
		});
	}catch(e){
		console.log("aliYunMorefunLogs-error:", e)
	}
}

module.exports = {
	aliYunMorefunLogs: aliYunMorefunLogs
};
